/*
 * 
 * Created on Jul 22, 2005
 */
package remato.client.view.editor.usertypes;

import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerDropAdapter;
import org.eclipse.swt.dnd.DropTargetListener;
import org.eclipse.swt.dnd.TransferData;

import remato.client.controller.RequirementPlugin;
import remato.client.model.PropertyDefWrapper;
import remato.client.model.facade.DNDTarget;
import remato.client.view.facade.IModelTableEditor;
import remato.client.view.util.ModelByteArrayTransfer;

/**
 * 
 * @author Petter L. H. Eide
 * @version $Id: UserDefinedTypesEditorPartDropAdapter.java,v 1.3 2006-02-19 16:29:37 petterei Exp $
 *
 */
public class UserDefinedTypesEditorPartDropAdapter extends ViewerDropAdapter implements DropTargetListener {

	PropertyDefWrapper target;
    
    /**
     * @param viewer
     */
    public UserDefinedTypesEditorPartDropAdapter(Viewer viewer) {
        super(viewer);
    }

    /**
     * @see org.eclipse.jface.viewers.ViewerDropAdapter#performDrop(java.lang.Object)
     */
    @Override
    public boolean performDrop(Object data) {
    	Object object = data;
    	System.out.println("Data-type at target: " + object.getClass().getName());
        if (object instanceof PropertyDefWrapper) {
            RequirementPlugin.log(getClass(), "Starting dnd..."  );
            return ((IModelTableEditor<PropertyDefWrapper>)((StructuredViewer)getViewer()).getContentProvider()).insertAfter((PropertyDefWrapper)object, target);
        }
        return false;
    }

    /**
     * @see org.eclipse.jface.viewers.ViewerDropAdapter#validateDrop(java.lang.Object, int, org.eclipse.swt.dnd.TransferData)
     */
    @Override
    public boolean validateDrop(@SuppressWarnings("hiding") Object target, @SuppressWarnings("unused") int operation, TransferData transferType) {
        boolean validateOk = false;
//        System.out.println("target instanceof PropertySpesification: " + (target instanceof PropertySpesification)) ;
//        System.out.println("target instanceof DNDTarget: " + (target instanceof DNDTarget)) ;
//        Object object = target;
//        System.out.println("source " + object.getClass().getName()) ;
        if (
                target instanceof PropertyDefWrapper
                && ModelByteArrayTransfer.getInstance().isSupportedType(transferType) 
                && target instanceof DNDTarget 
//                && ((DNDTarget)target).validTransfer(transferType)
                ) {
            validateOk = true;
            this.target = (PropertyDefWrapper) target ;
        }
        return validateOk;
    }

}
/**
 * 
 * Changelog:
 * 
 * $Log: UserDefinedTypesEditorPartDropAdapter.java,v $
 * Revision 1.3  2006-02-19 16:29:37  petterei
 * *** empty log message ***
 *
 * Revision 1.2  2006-01-30 21:52:32  petterei
 * implemented wrapper factory and lazy wrapper-instantiation of parents
 * implemented a "system" for each top-node type
 * added top-categories for all top-nodes
 * implemented some interfaces for the wrappers, and started using these
 *
 * Revision 1.1  2006-01-23 19:58:37  petterei
 * initial commit for client, fitting the alternative session implementation
 *
 * Revision 1.1  2005-12-03 14:38:48  petterei
 * *** empty log message ***
 *
 * Revision 1.1  2005/11/16 16:43:28  petterei
 * mye testing...
 *
 * Revision 1.5  2005/09/26 17:48:05  petterei
 * release conflicts, step 2
 *
 * Revision 1.3  2005/09/01 11:03:12  petterei
 * fixed dnd in user-defined-types-editor for windows
 *
 * Revision 1.2  2005/08/31 21:43:31  petterei
 * +partly fixed dnd
 *
 * Revision 1.1  2005/08/28 18:01:26  peide3
 * save in Eclipse-way
 * dynamic propertyspecifications bug fixed
 * dnd to deside order of property specification
 * ItemType to make convertion more understandable
 *
 *
 *
 */

